import { createStore } from 'vuex'
import { setItem, getItem } from '@/utils/storage'
const TOKEN_KEY = 'TOUDIAO_USER'

export default createStore({
  state: {
    // 存储当前用户信息 记得数据转化成JSON形式
    user: getItem(TOKEN_KEY)
  },
  getters: {
  },
  mutations: {
    setUser (state, data) {
      state.user = data
      // 放入本地localStorage 数据持久化 记得数据转化成字符串形式
      setItem(TOKEN_KEY, state.user)
    }
  },
  actions: {
  },
  modules: {
  }
})
